#include<bits/stdc++.h>
using namespace std;
#define M 100005
int n,a[M];
int mk[25];
void solve(){
    cin>>n;
    int anss=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int S=0;S<(1<<n);S++) {
      //  cout<<S<<endl;
        int ans=0;
        for(int i=1;i<=n;i++) {if((S>>(i-1))&1) mk[i]=1;
     //   cout<<mk[i]<<" ";
        }
        int p1=0,p2=0;
        for(int i=1;i<=n;i++) {
            if(mk[i]==1&&p1==0) {
                    p1=i;continue;}
            if(mk[i]==0&&p2==0) {p2=i;
            continue;}
            if(mk[i]==1){
                if(a[p1]==a[i]) ans+=a[i];
                p1=i;
            }
            if(mk[i]==0) {
                if(a[p2]==a[i]) ans+=a[i];
                p2=i;
            }
        }
    anss=max(anss,ans);
    }
    cout<<anss<<'\n';
}

int main(){
   // freopen("color.in","r",stdin);
   // freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        solve();
    memset(mk,0,sizeof(mk));
    }
    return 0;
}
